<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class slide_model extends CI_Model {

	public function get_vdo($per_page ,$uri ,$result_by)
	{
		if($this->uri->segment(1) == 'pvdo')
		{
			$this->db->limit($per_page ,$uri);
			$this->db->order_by($result_by);
		}
		
		$this->db->where('slide_status' ,0);
		$this->db->where('thumb_choose' ,1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');		
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function get_slide()
	{	
		$this->db->where('slide_status' ,1);
		$this->db->where('thumb_choose' ,1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');		
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function search($input ,$per_page ,$uri ,$result_by)
	{
		$this->db->limit($per_page ,$uri);
		$this->db->order_by($result_by);
		$this->db->like('vdo.vdo_name',$input['search']);
		$this->db->or_like('vdo.vdo_des',$input['search']);
		$this->db->or_like('vdo.vdo_tag',$input['search']);
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$this->db->group_by("vdo.vdo_id"); 
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function count_search($input)
	{
		$this->db->like('vdo.vdo_name',$input['search']);
		$this->db->or_like('vdo.vdo_des',$input['search']);
		$this->db->or_like('vdo.vdo_tag',$input['search']);
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$this->db->group_by("vdo.vdo_id"); 
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function get_profile($id)
	{
		$this->db->where('vdo_id',$id);		
		$this->db->join('server','server.server_id = vdo.server_id','left');
		$this->db->join('member','member.mem_id = vdo.mem_id','left');
		$this->db->join('category','category.category_id = vdo.category_id','left');
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function get_thumb($id)
	{
		$this->db->where('vdo_id',$id);
		$query = $this->db->get('vdo_thumb');
		return $query->result_array();
	}

	public function update_profile($input)
	{
		$this->db->where('vdo_id',$input['vdo_id']);
		$this->db->update('vdo',$input);
	}

	public function redirect($destination_file)
	{
		$this->db->select('vdo_id');
		$this->db->from('vdo');
		$this->db->where('vdo_rawfile',$destination_file);
		$query = $this->db->get();
		return $query->result_array();

	}

	public function get_category()
	{
		$query = $this->db->get('category');
		return $query->result_array();
	}

	public function sum_status($priority)
	{
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function update_slide($input)
	{
		$this->db->where('vdo_id' ,$input['vdo_id']);
		$this->db->update('vdo' ,$input);
	}

	public function check_slide($vdo)
	{
		$this->db->where('vdo_id',$vdo['vdo_id']);
		$query = $this->db->get('vdo');
		return $query->result_array();
	}

	public function check_remove_slide()
	{
		$this->db->where('slide_status' ,1);
		$query = $this->db->get('vdo');
		return $query->result_array();
	}
	
	public function report($vdo_id)
	{
		$this->db->where('vdo_id' ,$vdo_id);
		$query = $this->db->get('report_vdo');
		return $query->result_array();
	}

	public function delete_slide($vdo)
	{
		$this->db->where('vdo_id',$vdo['vdo_id']);
		$this->db->update('vdo',$vdo);
	}

	public function set_time($input)
	{
		$this->db->where('vdo_id',$input['vdo_id']);
		$this->db->update('vdo',$input);
	}


}